package edu.fiu.cis.personalize.server.graph.update;

import edu.fiu.cis.personalize.server.GraphUpdater;
import edu.fiu.cis.personalize.server.UpdateElement;
import edu.fiu.cis.personalize.server.graph.Node;
import edu.fiu.cis.personalize.server.graph.NodeType;

/**
 * This class will be synchronized and refactored.
 * 
 * @author Abhijith
 * 
 */
public abstract class GraphUpdate<N extends Node, M extends Node> {

	public final void update(N from, M to) {
		// perform the actual update
		double weight = computeWeight(from, to);
		from.setEdgeTo(to, weight);
		to.setEdgeFrom(from, weight);

		// System.out.println("f: " + from.getStringKey() + " t:"
		// + to.getStringKey() + " w:" + weight);

		GraphUpdater.enque(new UpdateElement(from.getId(), from.getType()));
		GraphUpdater.enque(new UpdateElement(to.getId(), to.getType()));

	}

	protected abstract double computeWeight(N node1, M node2);

	public final double getAuthorityTransferRate(N node1, M node2) {
		return 0.25;
	}

	abstract NodeType type1();

	abstract NodeType type2();

}
